﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryMangementSystem.BookManage
{
    public partial class PublishAdd : Form
    {
        public PublishAdd()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBoxPublishId.Text != "" && textBoxPublish.Text != ""&& textBoxPostcode!=null)
            {
                LibraryEntities1 library = new LibraryEntities1();
                Publisherlnfo publisher = new Publisherlnfo();
                if (textBoxPublishId.Text.Length > 4)
                {
                    MessageBox.Show("ID过长");
                    return;
                }
                publisher.PublisherId = textBoxPublishId.Text.Trim();
                publisher.Publisher = textBoxPublish.Text.Trim();
                publisher.Address = textBoxAddress.Text.Trim();
                publisher.Tel = textBoxTel.Text.Trim();
                publisher.Fax = textBoxFax.Text.Trim();
                if (textBoxPostcode.Text.Length>6) {
                    MessageBox.Show("邮编过长");
                    return;
                }
                publisher.Postcode = decimal.Parse(textBoxPostcode.Text);

                publisher.http = textBoxhttp.Text.Trim();
                library.Publisherlnfo.Add(publisher);
                int result = library.SaveChanges();
                String str = result == 1 ? "添加出版社成功" : "添加出版社失败";
                MessageBox.Show(str);
                this.DialogResult = DialogResult.OK;
                this.Close();

            }
            else
            {
                MessageBox.Show("有非空项");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
